<?php

namespace app\appapi\controller;


use app\data\model\LiveAppList;
use app\data\model\LiveAppproxy;

class Soft extends BaseController
{
    //获取更新
    public function getUpdate(){
        $userId = $this->checkTokenReturnUserId();
        $post = $this->request->post();
        if(!isset( $post['appName'], $post['packageName'], $post['versionName'], $post['versionCode'])) $this->error('缺少参数！');
        if(empty($post['appName']) || empty($post['packageName']) || empty($post['versionName']) || empty($post['versionCode'])) $this->error('参数不可为空！');

        $app = LiveAppList::mk()->field('update_versioncode,update_message,update_downloadurl')->where(['app_name'=>$post['appName'],'app_package'=>$post['packageName'],'deleted'=>0])->find();
        if(empty($app)) $this->error('不存在当前应用！');
        if($app['update_versioncode'] <= $post['versionCode']){
            $this->success('已是最新版本！');
        }else{
            $this->success('需要更新！',$app,200);
        }
    }
    //关于我们
    public function getAboutus(){
        $userId = $this->checkTokenReturnUserId();
        $post = $this->request->post();
        if(!isset( $post['appName'], $post['packageName'], $post['versionName'], $post['versionCode'])) $this->error('缺少参数！');
        if(empty($post['appName']) || empty($post['packageName']) || empty($post['versionName']) || empty($post['versionCode'])) $this->error('参数不可为空！');

        $app = LiveAppList::mk()->field('app_kefu_qrcode,app_kefu_msg')->where(['app_name'=>$post['appName'],'app_package'=>$post['packageName'],'deleted'=>0])->find();
        if(empty($app)) $this->error('不存在当前应用！');
        $this->success('获取成功',$app);
    }
    //加入我们
    public function getProxy(){
        $userId = $this->checkTokenReturnUserId();
        $post = $this->request->post();
        if(!isset( $post['appName'], $post['packageName'], $post['versionName'], $post['versionCode'])) $this->error('缺少参数！');
        if(in_array($post['packageName'],['com.live.luosina'])) $this->error('请联系管理员！');
        if(empty($post['appName']) || empty($post['packageName']) || empty($post['versionName']) || empty($post['versionCode'])) $this->error('参数不可为空！');
        if($post['versionCode'] < 8) $this->error('请安装最新版本进行下载');
        $app = LiveAppproxy::mk()->field('version_code,version_message,version_url')->where(['id'=>1])->find();
        $this->success('需要更新！',$app,300);
    }
}